home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 7 / Amiga Format AFCD07 (Dec 1996, Issue 91).iso / serious / shareware / programming / aros / exec / sumlibrary.c < prev    next >
C/C++ Source or Header  |  1996-09-12  |  3KB  |  120 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: sumlibrary.c,v 1.4 1996/08/13 13:56:09 digulla Exp $
  4.     $Log: sumlibrary.c,v $
  5.     Revision 1.4  1996/08/13 13:56:09  digulla
  6.     Replaced __AROS_LA by __AROS_LHA
  7.     Replaced some __AROS_LH*I by __AROS_LH*
  8.     Sorted and added includes
  9.  
  10.     Revision 1.3  1996/08/01 17:41:20  digulla
  11.     Added standard header for all files
  12.  
  13.     Desc:
  14.     Lang: english
  15. */
  16. #include <exec/execbase.h>
  17. #include <exec/alerts.h>
  18. #include <aros/libcall.h>
  19.  
  20. /*****************************************************************************
  21.  
  22.     NAME */
  23.     #include <clib/exec_protos.h>
  24.  
  25.     __AROS_LH1(void, SumLibrary,
  26.  
  27. /*  SYNOPSIS */
  28.     __AROS_LHA(struct Library *, library,A1),
  29.  
  30. /*  LOCATION */
  31.     struct ExecBase *, SysBase, 71, Exec)
  32.  
  33. /*  FUNCTION
  34.     Builds the checksum over a given library's jumptable and either puts
  35.     it into the library->lib_Sum field (if the library is marked as changed)
  36.     or compares it with this field and Alert()s at mismatch.
  37.  
  38.     INPUTS
  39.     library - Pointer to library structure.
  40.  
  41.     RESULT
  42.  
  43.     NOTES
  44.  
  45.     EXAMPLE
  46.  
  47.     BUGS
  48.  
  49.     SEE ALSO
  50.     AddLibrary(), RemLibrary(), MakeLibrary(), MakeFunctions(), InitStruct().
  51.  
  52.     INTERNALS
  53.  
  54.     HISTORY
  55.  
  56. ******************************************************************************/
  57. {
  58.     __AROS_FUNC_INIT
  59.  
  60.     UBYTE oldflags;
  61.     ULONG sum;
  62.  
  63.     /* Arbitrate for library base */
  64.     Forbid();
  65.  
  66.     /*
  67.     If the library checksumming is already in progress or if the
  68.     checksum is unused skip this part
  69.     */
  70.     if(library->lib_Flags&LIBF_SUMUSED&&!(library->lib_Flags&LIBF_SUMMING))
  71.     {
  72.     /* As long as the library is marked as changed */
  73.     do
  74.     {
  75.         ULONG *lp;
  76.  
  77.         /* Memorize library flags */
  78.         oldflags=library->lib_Flags;
  79.  
  80.         /* Tell other tasks: Summing in progress */
  81.         library->lib_Flags|=LIBF_SUMMING;
  82.         library->lib_Flags&=~LIBF_CHANGED;
  83.  
  84.         /* As long as the summing goes multitasking may be permitted. */
  85.         Permit();
  86.  
  87.         /* Build checksum. Note: library bases are LONG aligned */
  88.         sum=0;
  89.         /* Get start of jumptable */
  90.         lp=(ULONG *)((UBYTE *)library+library->lib_NegSize);
  91.         /* And sum it up */
  92.         while(lp<(ULONG *)library)
  93.         sum+=*lp++;
  94.  
  95.         /* Summing complete. Arbitrate again. */
  96.         Forbid();
  97.  
  98.         /* Remove summing flag */
  99.         library->lib_Flags&=~LIBF_SUMMING;
  100.  
  101.         /* Do it again if the library changed while summing. */
  102.     }while(library->lib_Flags&LIBF_CHANGED);
  103.  
  104.     /*
  105.         Alert() if the library wasn't marked as changed and if the
  106.         checksum mismatches.
  107.     */
  108.     if(!(oldflags&LIBF_CHANGED)&&library->lib_Sum!=sum)
  109.         Alert(AT_DeadEnd|AN_LibChkSum);
  110.  
  111.     /* Set new checksum */
  112.     library->lib_Sum=sum;
  113.     }
  114.  
  115.     /* All done. */
  116.     Permit();
  117.     __AROS_FUNC_EXIT
  118. } /* SumLibrary */
  119.  
  120.